<?php
/**
 *
 */
namespace app\common\model;
use think\Model;
use think\Db;

class Blh extends Model{

    public $token;
    public $app_id;
    public $app_key;
    public $base_url;
    //成功返回示例
   /* {
    "result":true,
    "errCode":"0000",
    "desc":"success",
    "data":Θ{
    "token":"68baa8c4ac4936f37cb2a9bc03ac82ad",
    "deadline":"2021-05-26 09:08:16"
    }
    }*/
    public $errcode=[
        "0000"=>"success",
        "3014"=>"客户单号已存在",
        "1001"=>"参数异常",
        "1004"=>"sign验证错误",
        "1005"=>"Tamptimes日期格式异常",
        "1006"=>"地址参数异常",
        "2001"=>"接口账号信息异常",
        "2002"=>"接口账号权限异常",
        "2003"=>"授权口令token调用次数超限",
        "2006"=>"授权口令token验证失败",
        "2009"=>"授权口令token失效",
        "3013"=>"商品信息异常",
        "5001"=>"商品编号信息异常",
        "5002"=>"商品详情异常",
        "5003"=>"京东商品库存异常",
        "3001"=>"订单类型异常",
        "3002"=>"订单来源异常",
        "3004"=>"地址类型异常",
        "3006"=>"订单基础信息异常",
        "3007"=>"订单商品信息异常",
        "3008"=>"订单商品数量异常",
        "3009"=>"无效商品编号",
        "3010"=>"商品已下架",
        "3011"=>"商品属性异常",
        "3012"=>"商品信息获取异常",
        "3015"=>"订单状态异常",
        "3016"=>"订单系统审核中",
        "4001"=>"通知消息数量异常",
        "4002"=>"通知消息ID异常",
        "9001"=>"系统繁忙",
        "9002"=>"下游接口问题",
        "9003"=>"IP异常",
        "9004"=>"无效接口",
        "9005"=>"接口权限问题",
        "9006"=>"接口已禁用",
        "9007"=>"账号已禁用",
        "8001"=>"短信条数不足"
    ];

    public function __construct(){
        parent::__construct();
        //parent::_initialize();
        $this->getToken();
    }

    /**权限类**/

    public function getToken(){

        $selectid = 1;
        $where=[
            'status'=>1,
            'id'=>$selectid
        ];
        $supply = Db::name('supply')->where($where)->find();

        $this->app_id=$app_id=$supply['app_id'];
        $this->app_key=$app_key=$supply['app_key'];
        $this->base_url=$supply['url'];

        if($supply['deadline'] > time()){

            $this->token= $supply['token'];
        }else{
            //app_id={app_id}:app_key={app_key}:tamptimes={tamptimes}
            $tamptimes=date('Y-m-d H:i:s',time());
            $str="app_id=".$app_id.":app_key=".$app_key.":tamptimes=".$tamptimes;
            $sign = strtoupper(md5($str));
            $url = $this->base_url.'/Index/getToken';
            $data=[
                'app_id'=>$this->app_id,
                'app_key'=>$this->app_key,
                'tamptimes'=>$tamptimes,
                'sign'=>$sign
            ];
            $data=json_encode($data);
            $res = http_json($url,$data);
            //正确返回：{"result":true,"errCode":"0000","desc":"success","data":{"token":"24c26a7a66c8239d0adffeb9fd9e4ad5","deadline":"2023-02-17 11:43:36"}}
            //错误返回：array(4) { ["result"]=> bool(false) ["errCode"]=> string(4) "1001" ["desc"]=> string(21) "tamptimes must exist!" ["data"]=> array(1) { ["requestId"]=> string(36) "EA0E8AF9-13B1-4FFE-869E-F194E2315BDE" } }
            $res = json_decode($res,true);
            if($res['result']==true){
                $this->token=$res['data']['token'];
                //记录
                $newToken=[
                    'token'=>$res['data']['token'],
                    'deadline'=>strtotime($res['data']['deadline']),
                ];

                @Db::name('supply')->where('id',$supply['id'])->update($newToken);
            }
        }

    }

    /**
     * @desc 返回数据伪造
     * @param $api
     * @return mixed
     * @date 2023-02-17 15:35
     */
    function fake($api){
        $fake= [
            'getNotics'=>'{"result":true,"errCode":"0000","desc":"success","data":{"notice_num":100,"notice_list":[{"notice_id":146,"type":1,"result":{"itemId":"24"},"time":"2020-07-30 15:31:34"},{"notice_id":147,"type":5,"result":{"itemId":"24","settle_price":"490"},"time":"2020-07-30 15:31:45"},{"notice_id":148,"type":3,"result":{"itemId":"24","state":1},"time":"2020-07-30 15:31:45"},{"notice_id":149,"type":1,"result":{"itemId":"25"},"time":"2020-07-30 15:34:10"},{"notice_id":150,"type":1,"result":{"itemId":"26"},"time":"2020-07-30 15:34:10"},{"notice_id":151,"type":1,"result":{"itemId":"27"},"time":"2020-07-30 15:34:10"},{"notice_id":152,"type":5,"result":{"itemId":"25","settle_price":"7158.14"},"time":"2020-07-30 15:34:30"},{"notice_id":153,"type":3,"result":{"itemId":"25","state":1},"time":"2020-07-30 15:34:30"},{"notice_id":154,"type":5,"result":{"itemId":"26","settle_price":"8095.29"},"time":"2020-07-30 15:34:46"},{"notice_id":155,"type":3,"result":{"itemId":"26","state":1},"time":"2020-07-30 15:34:46"},{"notice_id":156,"type":5,"result":{"itemId":"27","settle_price":"7158.24"},"time":"2020-07-30 15:34:57"},{"notice_id":157,"type":3,"result":{"itemId":"27","state":1},"time":"2020-07-30 15:34:57"},{"notice_id":158,"type":4,"result":{"itemId":"25","sell_price":"5500.00"},"time":"2020-07-30 15:47:26"},{"notice_id":159,"type":4,"result":{"itemId":"25","sell_price":"5500.00"},"time":"2020-07-30 15:47:26"},{"notice_id":160,"type":4,"result":{"itemId":"26","sell_price":"5200.00"},"time":"2020-07-30 15:47:26"},{"notice_id":161,"type":4,"result":{"itemId":"27","sell_price":"5000.00"},"time":"2020-07-30 15:47:26"},{"notice_id":162,"type":3,"result":{"itemId":"26","state":0},"time":"2020-07-30 15:52:28"},{"notice_id":163,"type":3,"result":{"itemId":"25","state":0},"time":"2020-07-30 15:52:28"},{"notice_id":248,"type":12,"result":{"order_sn":"V200731105308608296408","itemId":"34","cid":null,"code":null,"deadline":null},"time":"2020-08-01 11:28:25"},{"notice_id":249,"type":12,"result":{"order_sn":"V200731111016552195817","itemId":"35","cid":null,"code":null,"deadline":null},"time":"2020-08-01 11:28:25"},{"notice_id":250,"type":10,"result":{"order_sn":"S200731152652057706166","itemId":"38","number":"5","express_name":"SF","express_code":"123123123"},"time":"2020-08-01 11:28:25"},{"notice_id":251,"type":10,"result":{"order_sn":"S200731190838635224847","itemId":"39","number":"1","express_name":"申通快递","express_code":"SF584141"},"time":"2020-08-01 11:28:25"},{"notice_id":252,"type":10,"result":{"order_sn":"S200801104354584763523","itemId":"40","number":"4","express_name":"申通快递","express_code":"SF124i1j241"},"time":"2020-08-01 11:28:25"},{"notice_id":253,"type":1,"result":{"itemId":"41"},"time":"2020-08-01 13:12:02"},{"notice_id":254,"type":5,"result":{"itemId":"41","settle_price":"3"},"time":"2020-08-01 13:12:42"},{"notice_id":255,"type":3,"result":{"itemId":"41","state":1},"time":"2020-08-01 13:12:42"},{"notice_id":256,"type":12,"result":{"order_sn":"V200801131259252367247","itemId":"41","cid":null,"code":null,"deadline":null},"time":"2020-08-01 13:16:25"},{"notice_id":257,"type":99,"result":{"order_sn":"S200803092633182283788"},"time":"2020-08-03 09:27:58"},{"notice_id":258,"type":99,"result":{"order_sn":"S200803102914748297659"},"time":"2020-08-03 10:30:35"},{"notice_id":259,"type":99,"result":{"order_sn":"S200803103113762104136"},"time":"2020-08-03 10:32:40"},{"notice_id":260,"type":99,"result":{"order_sn":"S200803112106108183729"},"time":"2020-08-03 11:24:53"},{"notice_id":261,"type":99,"result":{"order_sn":"S200803112631067121111"},"time":"2020-08-03 11:27:50"},{"notice_id":262,"type":12,"result":{"order_sn":"V200731105404737716288","itemId":"34","cid":null,"code":null,"deadline":null},"time":"2020-08-04 09:56:05"}]}}'
        ];
        return $fake[$api];
    }
    /**
     * @title
     * @desc 格式化返回结果
     * @date 2023-02-17 11:17
     */
    public function res(){

    }
    /****通知类***/
    /**
     * @title
     * @desc 查询通知消息
     * @date 2023-02-17 11:11
     */
    public function getNotics(){
        $api = '/Notic/getNotics';
        $url = $this->base_url.$api;
        $post=['token'=>$this->token];
        //$res=http_json($url,$post);

        $res= $this->fake('getNotics');

        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @title
     * @desc 删除通知消息
     * @param $notice_ids
     * @date 2023-02-17 11:20
     */
    public function doNotics($notice_ids){
        $api = '/Notic/doNotics';
        $url = $this->base_url.$api;

        if(is_array($notice_ids)){
            $notice_ids = implode(',',$notice_ids);
        }
        $post=[
            'token'=>$this->token,
            'notice_ids'=>$notice_ids//参数异常:notice_ids,if no
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /****商品***/
    /**
     * @title
     * @desc 查询分类列表
     * @date 2023-02-17 11:31
     */

    public function getCategorys(){
        $api = '/Product/getCategorys';
        $url = $this->base_url.$api;
        $post=['token'=>$this->token];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @title
     * @desc 查询品牌列表
     * @date 2023-02-17 11:31
     */

    public function getBrandList(){
        $api = '/Product/getBrandList';
        $url = $this->base_url.$api;
        $post=['token'=>$this->token];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @title
     * @desc 查询商品ID
     * @date 2023-02-17 11:31
     */

    public function getGoodsId(){
        $api = '/Product/getGoodsId';
        $url = $this->base_url.$api;
        $post=['token'=>$this->token];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @title
     * @desc 查询商品详情
     * @param $notice_ids
     * @date 2023-02-17 11:20
     */
    public function getGoodInfo($itemId){

        $api = '/Product/getGoodInfo';
        $url = $this->base_url.$api;

        $post=[
            'token'=>$this->token,
            'itemId'=>intval($itemId)//参数异常:notice_ids,if no
        ];
        $res=http_json($url,$post);
        $res=urldecode($res);
        $res = json_decode($res,true);
        //array(4) { ["result"]=> bool(false) ["errCode"]=> string(4) "3013" ["desc"]=> string(25) "商品查询异常:100023" ["data"]=> array(1) { ["requestId"]=> string(36) "10D80AC3-BD6C-43D1-84BE-6087B8DC01E3" } }
        return $res;
    }

    /**
     * @title
     * @desc 查询直充参数模板
     * @param $itemId
     * @date 2023-02-17 11:20
     */
    public function getRechargeTemplate($itemId){

        $api = '/Product/getRechargeTemplate';
        $url = $this->base_url.$api;

        $post=[
            'token'=>$this->token,
            'itemId'=>$itemId//参数异常:notice_ids,if no
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**#################公共##########################################################################################################################################################**/
    /**
     * @title
     * @desc 查询快递公司列表
     * @date 2023-02-17 11:31
     */

    public function getExpressList(){
        $api = '/Express/getExpressList';
        $url = $this->base_url.$api;
        $post=['token'=>$this->token];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }
    /**
     * @title
     * @desc 发送短信
     * @date 2023-02-17 11:31
     */

    public function getSendSms($mobile,$content,$sign){
        $api = '/Sms/SendSms';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'mobile'=>$mobile,
            'content'=>$content,
            'sign'=>$this->$sign,
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**#################地址库##########################################################################################################################################################**/


    /**
     * @title
     * @desc 查询地址库列表（省级
     * @date 2023-02-17 11:31
     */

    public function getProvince(){
        $api = '/Area/getProvince';
        $url = $this->base_url.$api;
        $post=['token'=>$this->token];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @title
     * @desc 查询地址库列表（省级
     * @date 2023-02-17 11:31
     */

    public function getCity($area_id){
        $api = '/Area/getCity';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'area_id'=>$area_id
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @title
     * @desc 查询地址库列表（省级
     * @date 2023-02-17 11:31
     */

    public function getCounty($area_id){
        $api = '/Area/getCounty';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'area_id'=>$area_id
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }
    /**
     * @title
     * @desc 查询地址库列表（省级
     * @date 2023-02-17 11:31
     */

    public function getTown($area_id){
        $api = '/Area/getTown';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'area_id'=>$area_id
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }
    /**
     * @title
     * @desc 查询地址库列表（省级
     * @date 2023-02-17 11:31
     */

    public function getAreaName($area_ids){
        $api = '/Area/getAreaName';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'area_ids'=>$area_ids
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @title
     * @desc 查询地址库列表（省级
     * @date 2023-02-17 11:31
     * $area_ids至少要有2个逗号，即3级地址
     */

    public function getValid($area_ids){
        $api = '/Area/getValid';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'area_ids'=>$area_ids
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @title
     * @desc 批量查询地址区域描述
     * @date 2023-02-17 11:31
     * $area_ids至少要有2个逗号，即3级地址
     */

    public function multiGetAreaDesc($area_ids){
        $api = '/Area/multiGetAreaDesc';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'area_ids'=>$area_ids
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**#################库存##########################################################################################################################################################**/


    /**
     * @desc
     * @param $product
     * @param $product=[['itemId'=>64,'number'=>10],['itemId'=>65,'number'=>8],''''],$location=['province'=>1,'city'=>23,'country'=>'2342','town'=>'12344']
     * @date 2023-02-17 13:38
     */
    public function getStoreAsNum($products,$location){

        $api = '/Store/getStoreAsNum';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'products'=>$products,
            'province'=>$location['province'],
            'city'=>$location['city'],
            'county'=>$location['county'],
            'town'=>$location['town']
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @desc 查询商品区域库存状态
     * @param itemIds='1,2,3'
     * @param ,$location=['province'=>1,'city'=>23,'country'=>'2342','town'=>'12344']
     * @date 2023-02-17 13:38
     */
    public function getRegionStore($itemIds,$location){

        $api = '/Store/getRegionStore';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'itemIds'=>$itemIds,
            'province'=>$location['province'],
            'city'=>$location['city'],
            'county'=>$location['county'],
            'town'=>$location['town']
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**#################订单管理##########################################################################################################################################################**/


    /**
     * @desc 实物商品订单确认
     * @param itemIds='1,2,3'
     * @param ,$goods=[['itemId'=>89,'number'=>12,'price'=>2.34],['itemId'=>89,'number'=>12,'price'=>2.34]]
     * @date 2023-02-17 13:38
     */
    public function createEntityOrder($order,$goods,$sendcms=1){

        $api = '/Order/createEntityOrder';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'orderId'=>$order['orderId'],
            'shouhuo_name'=>$order['shouhuo_name'],
            'shouhuo_phone'=>$order['shouhuo_phone'],
            'provinceId'=>$order['provinceId'],
            'cityId'=>$order['cityId'],
            'countyId'=>$order['countyId'],
            'townId'=>$order['townId'],
            'note'=>$order['note'],
            'products'=>$goods,
            'sendcms'=>$sendcms
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }
    /**
     * @desrJD商品订单确认
     * @param itemIds='1,2,3'
     * @param ,$products=[['itemId'=>89,'number'=>12,'price'=>2.34],['itemId'=>89,'number'=>12,'price'=>2.34]]
     * @date 2023-02-17 13:38
     */
    public function createJdOrder($order,$products,$sendcms=1){

        $api = '/Order/createJdOrder';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'orderId'=>$order['orderId'],
            'shouhuo_name'=>$order['shouhuo_name'],
            'shouhuo_phone'=>$order['shouhuo_phone'],
            'provinceId'=>$order['provinceId'],
            'cityId'=>$order['cityId'],
            'countyId'=>$order['countyId'],
            'townId'=>$order['townId'],
            'note'=>$order['note'],
            'products'=>$products,
            'sendcms'=>$sendcms
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @desc 直充订单创建
     * @param $order
     * @param $products
     * @param $sendcms
     * @date 2023-02-17 14:26
     */
    public function createRechargeOrder($order,$products,$sendcms){
        $api = '/Order/createRechargeOrder';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'orderId'=>$order['orderId'],
            'shouhuo_phone'=>$order['shouhuo_phone'],
            'confirmModel'=>$order['confirmModel'],
            'note'=>$order['note'],
            'sendcms'=>$sendcms,
            'products'=>$products
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }
    /**
     * @desc 卡券订单创建
     * @param $order
     * @param $products=[['itemId'=>89,'number'=>12,'price'=>2.34],['itemId'=>89,'number'=>12,'price'=>2.34]]
     * @param $sendcms
     * @date 2023-02-17 14:26
     */
    public function createVirtualOrder($order,$products,$sendcms){
        $api = '/Order/createVirtualOrder';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'orderId'=>$order['orderId'],
            'shouhuo_phone'=>$order['shouhuo_phone'],
            'confirmModel'=>$order['confirmModel'],
            'note'=>$order['note'],
            'sendcms'=>$sendcms,
            'products'=>$products
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @desc 【4.2】订单统一确认
     * @param $order_sn
     * @date 2023-02-17 14:26
     */
    public function confirmOrder($order_sn){
        $api = '/Order/confirmOrder';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'order_sn'=>$order_sn,
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }
    /**
     * @desc 【4.3】订单统一取消（未确认订单）
     * @param $order_sn
     * @date 2023-02-17 14:26
     */
    public function cancelOrder($order_sn){
        $api = '/Order/cancelOrder';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'order_sn'=>$order_sn,
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }
    /**
     * @desc 【4.7】订单详情统一查询
     * @param $order_sn
     * @date 2023-02-17 14:26
     */
    public function getOrderInfo($order_sn){
        $api = '/Order/getOrderInfo';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'order_sn'=>$order_sn,
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }
    /**
     * @desc 【4.6】反查订单详情（客户单号）
     * @param $customer_no
     * @date 2023-02-17 14:26
     */
    public function getOrderInfoByCustomer($customer_no){
        $api = '/Order/getOrderInfoByCustomer';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'customer_no'=>$customer_no,
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }


    /**
     * @desc 【4.4】查询实物订单配送信息
     * @param $order_sn
     * @date 2023-02-17 14:26
     */
    public function getOrderShipment($order_sn){
        $api = '/Order/getOrderShipment';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'order_sn'=>$order_sn,
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }



    /**
     * @desc 【4.5】查询实物订单包裹信息
     * @param $order_sn
     * @param $nums
     * @date 2023-02-17 14:26
     */
    public function getOrderExpress($order_sn,$nums){
        $api = '/Special/getOrderExpress';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'nums'=>$nums,
            'order_sn'=>$order_sn,
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }
    /**#################订单管理##########################################################################################################################################################**/

    /**
     * @desc 【8.1】查询服务单详情
     * @param $serviceSn - from 百礼汇
     * @date 2023-02-17 14:26
     */
    public function getSaleafterDetail($serviceSn){
        $api = '/Saleafter/getDetail';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'serviceSn'=>$serviceSn,
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @desc 【8.2】查询服务单申请原因列表
     * @param $nature 1-int-自营实物订单,4-int-京东订单
     * @param $type 2-退货 3-换货
     * @date 2023-02-17 15:07
     */
    public function getApplyReasonList($nature,$type){
        $api = '/Saleafter/getApplyReasonList';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'nature'=>$nature,
            'type'=>$type,
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }
    /**
     * @desc 【8.2】查询服务单申请原因列表
     * @date 2023-02-17 15:07
     */
    public function getSaleafterApplyAuth($orderNo,$itemId){
        $api = '/Saleafter/getApplyAuth';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'orderNo'=>$orderNo,
            'itemId'=>$itemId,
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @desc 【8.4】创建售后服务单（订单取消）
     * @param $orderNo
     * @date 2023-02-17 15:11
     */
    public function applyOrderClose($orderNo){
        $api = '/Saleafter/applyOrderClose';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'orderNo'=>$orderNo,
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }


    /**
     * @desc 【8.5】创建售后服务单（订单商品退货）
     * @param $order
     * @date 2023-02-17 15:11
     */
    public function applyOrderProductReturn($order){
        $api = '/Saleafter/applyOrderProductReturn';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'orderNo'=>$order['orderNo'],
            'itemId'=>$order['itemId'],
            'reason'=>$order['reason'],
            'desc'=>$order['desc'],
            'mobile'=>$order['mobile'],
            'send'=>[
                'contacts'=>$order['contacts'],
                'contactsPhone'=>$order['contactsPhone'],
                'address'=>$order['address'],
            ]
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }

    /**
     * @desc 【8.6】创建售后服务单（订单商品换货）
     * @param $order
     * @date 2023-02-17 15:11
     */
    public function applyOrderProductExchange($order){
        $api = '/Saleafter/applyOrderProductExchange';
        $url = $this->base_url.$api;
        $post=[
            'token'=>$this->token,
            'orderNo'=>$order['orderNo'],
            'itemId'=>$order['itemId'],
            'reason'=>$order['reason'],
            'desc'=>$order['desc'],
            'mobile'=>$order['mobile'],
            'send'=>[
                'contacts'=>$order['contacts'],
                'contactsPhone'=>$order['contactsPhone'],
                'address'=>$order['address'],
            ],
            'receive'=>[
                'contacts'=>$order['contacts'],
                'contactsPhone'=>$order['contactsPhone'],
                'address'=>$order['address'],
            ]
        ];
        $res=http_json($url,$post);
        $res = json_decode($res,true);
        return $res;
    }


}
